/*
 * FB Test Users
 *
 * http://fql-builder.mariogarcia.biz
 * http://www.facebook.com/mariogarcia.ar 
 *
 * Copyright (c) 2011 - 2012 Mario Garcia
 *
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

// Global Variables
var _wrapper;
var _sidebar;
var _fb_tables;
var _panel;
var _console;
var _console_query;
var _fb_tables_desktop = {};
var _z_index = 100;
var _console_run;

// DOM is ready
jQuery(function(){

    //Init var
    _wrapper = jQuery('#wrapper');
    _sidebar = jQuery('#sidebar');
    _fb_tables = jQuery('#fb-tables');
    _panel = jQuery('#panel');
    _console = jQuery('#console');
    _console_query = jQuery('#console_query');
    _console_run = jQuery('#console_run');
    initTree();
//     initRun();
});


/**
 *  Init TreeView 
 *  
 *  Tables initialization   
 *
 */ 
function initTree(){
    
    function _onActivate(node){
        menu(node);
    }
    
    var _config = {
        onActivate: _onActivate,
        initAjax: {
            url: "data/menu.php"
        }
    }
    _fb_tables.dynatree(_config);
} 

function menu(item){
//     var _fx = '_'+item.data.key+'();';
//     eval(_fx)

    var _key = item.data.key;
    _menu_ajax_call(_key);
}

function _menu_ajax_call(pAction){
    _wrapper.block();
    var _url = 'data/fb-run.php';
    var _data = {'action':pAction};
    
    $.post(_url,_data,_onSuccess);
    function _onSuccess(pData){

        var _data = jQuery(pData);
        _wrapper.unblock(); 
        var _config = {
            message: _data
            , css: {
                width: '90%',
                height: '400px'
            }
        }
        _wrapper.block(_config);     
    }
}
